package com.example.demo.utils;

import com.example.demo.entity.rep.RuleRep;
import com.example.demo.service.WecomService;
import org.apache.ibatis.session.ResultContext;
import org.apache.ibatis.session.ResultHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class NotificationHandler implements ResultHandler<Object> {

    @Autowired
    private WecomService wecomService;

    @Override
    public void handleResult(ResultContext<?> resultContext) {
        RuleRep ruleRep = (RuleRep) resultContext.getResultObject();
        List<RuleRep> list = (List<RuleRep>) resultContext.getResultObject(); // 这里需要更正，因为只有一个对象
        notify(ruleRep, list);
    }

    private void notify(RuleRep ruleRep, List<RuleRep> list) {
        String markdown = "告警名称：" + ruleRep.getName() + "\n" + "告警结果：" + list.size();
//        wecomService.notify(ruleRep.getAlarmPlatformConfig(), markdown);
    }
}
